import { reactive } from 'vue';

export const queryParams = reactive({
  featureCode: '',
  callTimeStart: '',
  callTimeEnd: '',
  inputType: '',
  inputParams: '',
  xqdwCodes: '',
  classifyCodes: '',
  callSummaryCodes: '',
  dealSummaryCodes: '',
  size: 10,
  page: 1,
  //   seriesType: 'default',
});

export const getParamsCodes = data => {
  const tempMap = {};
  data.forEach(el => {
    if (tempMap[el.attributes.type]) {
      tempMap[el.attributes.type].push(el.code);
    } else {
      tempMap[el.attributes.type] = [el.code];
    }
  });
  const resultMap = {
    ai: '',
    jq: '',
    fk: '',
    xqdw: '',
  };
  Object.keys(resultMap).forEach(k => (resultMap[k] = tempMap[k] ? tempMap[k].toString() : ''));
  return resultMap;
};

export const getParamsNames = (data, type = 'array') => {
  const tempName = {};
  data.forEach(el => {
    if (tempName[el.attributes.type]) {
      tempName[el.attributes.type].push(el.code);
    } else {
      tempName[el.attributes.type] = [el.code];
    }
  });
  if (type === 'string') {
    Object.keys(tempName).forEach(key => {
      tempName[key] = tempName[key].toString();
    });
  }
  return tempName;
};
